/**
 * 获取当前页面或指定页面地址的参数值
 * @param {String} name 参数名
 * @param url {String} url 页面地址，默认当前页面地址
 * @returns {string}
 */
function getQuery(name, url) {
    // 参数：变量名，url为空则表从当前页面的url中取
    const u = url || window.location.search.replace('&amp;', '&').replace(/\/$/, '');
    const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
    const r = u.substr(u.indexOf('?') + 1).match(reg);
    return r != null ? r[2] : '';
}

/**
 * 浏览器内核
 * @type {string}
 */
const ua = window.navigator.userAgent.toLocaleLowerCase(); // 当前浏览器
const href = window.location.href;
const isIos = /iphone|ipod|ipad/.test(ua);
const isWx = ua.indexOf('micromessenger') !== -1;
const isAndroid = /android/.test(ua);
const isNative = /from:ehomeapp/.test(ua);
const isLogin = /^on/g.test(getQuery('isLogin'));
const isDev = (process.env.NODE_ENV == 'development') || (href.indexOf('http://192.168.3.136:8080') !== -1);
const isTest = (href.indexOf('http://www.dabowei.com') !== -1); //                                                // lqsz-d00268   lqsz-D00270
const isPrd = (href.indexOf('http://120.78.145.131:81') !== -1); // 生产外网或内网


export {
    isIos,
    isWx,
    isAndroid,
    isNative,
    isLogin,
    isDev,
    isTest,
    isPrd,
};